<?php echo $this->element('displayHeader'); ?>

<!-- View Site Inventory -->
<?php $user = $session->read('Auth.User'); ?>
<div class="viewSiteInventory">
        <?php echo $ajax->form('CustProductSites', 'post', array('update' => 'content', 'indicator' => 'indicator','url' => array('controller' => 'supplier_customer_inventories', 'action' => 'change_view_site/' . $customer_id)));
        echo 'View Site Inventory ' . $form->select('view_site_inventory', $this->requestAction('supplier_customer_inventories/site_list/'. $customer_id),
            $user['Extend']['view_site_inventory'],
            array('id' => 'viewSiteInventory', 'name' => 'data[view_site_inventory]'), false);
        echo $form->submit('submit', array('class' => 'hide', 'id' =>'viewSiteInventorySubmit'));
        echo $form->end();
        ?>
    <script type="text/javascript">
        $j("#viewSiteInventory").bind("change", function(event) {
            $j("#viewSiteInventorySubmit").trigger("click");
        });
    </script>
</div>

<div class="toolbar">
    <?php echo $this->element('toolbar', array('buttons' => array(array('search' => array('controller' => 'supplier_customer_inventories')), array('refresh' => array('params' => $customer_id))))); ?>
</div>
<?php if (empty($this->data)) : // ถ้าไม่มีข้อมูล ?>
<?php echo $this->element('dataNotFound'); ?>
<? else : // ถ้ามีข้อมูล ?>
    <?php $paginator->options(array('update' => 'content', 'indicator' => 'indicator', 'url' => array('controller' => 'supplier_customer_inventories', 'action' => 'display/' . $customer_id))); ?>
    <?php echo $this->element('dataCaptionLimit', array('controller' => 'supplier_customer_inventories', 'action' => 'display/' . $customer_id)); ?>
    <?php $cur = $paginator->counter(array('format' => '%start%')); ?>

<table class="data">
    <thead>
        <tr>
            <th class="no"><?php echo $paginator->sort('No', 'id'); ?></th>
            <th width="130px"><?php echo $paginator->sort('Stock Code', 'CustProductSite.stock_code'); ?></th>
            <th width="135px"><?php echo $paginator->sort('ITS Part no.', 'Product.part_no'); ?></th>
            <th>Category</th>
            <th>Brand</th>
            <th><?php echo $paginator->sort('Model', 'Product.model'); ?></th>
            <th width="100px"><?php echo $paginator->sort('Current Stock', 'CustProductSite.current_stock'); ?></th>
            <th width="80px"><?php echo $paginator->sort('Min Stock', 'CustProductSite.min_stock'); ?></th>
            <th width="80px"><?php echo $paginator->sort('Max Stock', 'CustProductSite.max_stock'); ?></th>
            <th class="action">&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach($this->data as $i => $data):
            $current_stock = $data['CustProductSite']['current_stock'];
            $min_stock = $data['CustProductSite']['min_stock'];
            $max_stock = $data['CustProductSite']['max_stock'];
            ?>
        <tr class="<?php
                if (empty($max_stock) && empty($min_stock)) {
                    echo (($i + 1) % 2 == 0)? 'even-cell' : 'odd-cell';
                } else {
                    echo $current_stock < $min_stock? 'min-stock': ($current_stock < $max_stock? 'max-stock': ($current_stock >= $max_stock? 'green': ''));
                }
                    ?>">
            <td class="center"><?php echo $i + 1; ?></td>
            <td><?php echo $data['CustProductSite']['stock_code']; ?></td>
            <td><?php echo $data['Product']['part_no']; ?></td>
            <td><?php echo isset($data['Product']['Category']['name'])? $data['Product']['Category']['name'] : '-'; ?></td>
            <td><?php echo $data['Product']['Brand']['name']; ?></td>
            <td><?php echo $data['Product']['model']; ?></td>
            <td class="text-right"><?php echo $current_stock; ?></td>
            <td class="text-right"><?php echo $min_stock; ?></td>
            <td class="text-right"><?php echo $max_stock; ?></td>
            <td>
                <?php echo $ajax->link( $html->image('icon/edit.png', array('title' => 'view', 'alt' => 'view')), '/supplier_customer_inventories/view/' . $data['CustProductSite']['id'],
                array('indicator' => 'indicator', 'update' => 'content'), null, false); ?>
            </td>
        </tr>
            <?php endforeach; ?>
    </tbody>
</table>
    <?php echo $this->element('paging'); ?>
<div class="caption">
    <span class="min-stock rect"></span> Current Stock is less than Min Stock.
    <span class="max-stock rect"></span> Current Stock is less than Max Stock.
    <span class="green rect"></span> Current Stock is higher than Max Stock.
</div>

<? endif; ?>
